<template>
	<view class="content">
		
		<lonjin-form 
			@submit="submit" 
			:formData="formData" 
			@updateValue="updateValue" 
			@uploadPicture="uploadPicture"
			:config="config"
			@uploadMedia="uploadMedia"
			>
		</lonjin-form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				formData: {},
				config: [
					{
						label: '用户名',
						placeholder: '请输入',
						key: 'username',
						type: 'input',
						inputType: 'text',
					},
					
					{
						label: '手机号',
						placeholder: '请输入',
						key: 'phone',
						type: 'input',
						inputType: 'number',
					},
					{
						label: '单选',
						placeholder: '请选择',
						key: 'sex',
						type: 'picker',
						options: [
							{
								label: '男',
								value: '1'
							},
							{
								label: '女',
								value: '0'
							},
							
						],
					},
					
					{
						label: '地址',
						placeholder: '请输入地址',
						key: 'userarea',
						type: 'textarea',
					},
					
				]
			}
		},
		onLoad() {
				this.request({
					url:'/user/find',
					methods:'GET',
				}).then(res=>
				{
					if(res.code==='1')
					{
						this.formData = res.data
					}
				}).catch(err=>
				{
					console.log("系统错误")
				})
		},
		methods: {
			updateValue(val) {
			                this.formData = val
			            },

			// 提交数据
			submit(val) {
				console.log(val)
				console.log(this.formData)
				this.request({
					url:'/user/reset',
					methods:'GET',
					data:
					{
						username: this.formData.username,
						password:this.formData.password,
						sex:this.formData.sex,
						userarea:this.formData.userarea,
						phone:this.formData.phone,
					},
				
				}).then(res=>
				{
					if(res.data==='1')
					{
						console.log("成功")
						uni.navigateTo({
							url:'/pages/me/me'
						})
					}
					else
					{
						console.log("失败")
					}
				}).catch(err=>
				{
					console.log("系统错误")
				})
			},
			
			// 图片/视频上传
			
			
			
		}
	}
</script>

<style>
	.title{
		width: 100%;
		font-size: 30rpx;
		margin-bottom: 32rpx;
		font-weight: bold;
		padding: 32rpx 32rpx 0 32rpx;
	}
	.content {
		width: 100%;
	}
</style>
